@echo off
rem **************************************************************************
rem    Build the Surveyor Executeable
rem     

rem **************************************************************************
rem Environment

rem # %0 is fully-qualified command line bat file was run from, ~dp grabs the folder  
set ROOT=%~dp0..\..\
if not exist %ROOT% goto END:

set STARTDIR=%CD%
set BUILD=%ROOT%\packaging\windows
set STAGING=%BUILD%\STAGING
set TEST=%BUILD%\OUT
set CORE=%ROOT%\surveyor

echo                                                                          .
echo **************************************************************************
echo Prepare Folders
echo                                                                          .

call PycClean.bat %CORE%

del /s /q %STAGING%
del /s /q %TEST%

if not exist %STAGING% md %STAGING%
if not exist %TEST% md %TEST%


echo                                                                          .
echo **************************************************************************
echo Create Command-Line Executeable
echo                                                                          .

cd %STAGING%

rem # Move necessary marerials into place for the build
copy %CORE%\*.* /y
copy %BUILD%\SetupExe.py
copy %BUILD%\surveyor.ico 

ren README README.txt
ren LICENSE LICENSE.txt

mkdir framework
copy %CORE%\framework\*.py framework /y

mkdir csmodules
copy %CORE%\csmodules\*.py csmodules /y

rem # Create the EXE with Py2Exe
python SetupExe.py py2exe 

rem # Cleanup Py2Exe items we do not need to distribute
del %STAGING%\dist\w9xpopen.exe


echo                                                                          .
echo **************************************************************************
echo  Finish up
echo                                                                          .

cd %TEST%
xcopy %STAGING%\dist\* /s 

:END
cd %STARTDIR%

